// 绑定仓库
	levelSelect.init('/WBILL-webapp/commondata/getwarehouse.json', 'Warehouse',0,1);
	// 绑定经手人
	levelSelect.init('/WBILL-webapp/commondata/getbranchuser.json?param=2&search=1', 'OperUser',0,1);
	// 绑定制单人
	levelSelect.init('/WBILL-webapp/commondata/getbranchuser.json?type=1&search=1', 'CreateUser',0,1,1);
	
	function loadSearchSelect(){
		// 绑定门店
		var branchObj=$(".expertSearch").find("select[id*='Branch']");
		if(branchObj!=null&&branchObj!=undefined){
			$.ajax({
				dataType:"json",
				cache:false,
				async:false,
				url:"/WBILL-webapp/commondata/getbranch.json",
				type:"post",
				success:function(o){
					if(o.Items!=null){
						branchObj.each(function(){
							for(var i=0;i<o.Items.length;i++){
								$(this).append("<option value='"+o.Items[i]["value"]+"'>"+o.Items[i]["text"]+"</option>");
							}
						});
					}else{
						$(this).hide();
					}
				},
				error:function(){
					showErrorMsg("绑定门店下拉框失败");
				}
			});
		}
	}
	
	function bindcustomer() {
		var autoCompleteTextbox = $("#txbCr");
		if (!!autoCompleteTextbox) {
			// 智能提示 编号、名称、规格、单位、条形码、库存数量
			var productheader = {
				clientcode : "客户编号",
				clientname : "客户名称"
					/*,
				clientlink : "联系人",
				clienttel : "联系电话",
				clientaddress:"地址"*/
			};
			$("#txbCr").autoComplete({
				header : productheader,
				url : "/WBI-webapp/ClientInfo/FuzzyQuery.htm?branchid=" + $("#choose-warehouse-parentval").val(),
				width : 400,
				businame:'cs',
				selected : function(o) {
					if ($("#choose-warehouse-val").val() == "") {
						showErrorMsg("请选择出库仓库!");
						return;
					}
					$("#crvalue").val(o["clientid"]);
					$("input[name='hidisgetnearprice']").val("0");
					$("#txbCr").val(o["clientname"]);
					$("#txclientlink").val(o["clientlink"]);
					$("#txclienttel").val(o["clienttel"]);
					$("#txreceaddress").val(o["clientaddress"]);
					if(parseFloat(o["receamt"])!=0||($("#thisreceamt").val()!=""&&parseFloat($("#thisreceamt").val())!=0)){
						$("#divreceamt").show();
					}else{
						$("#divreceamt").hide();
					}
					if(o["receamt"]==null||o["receamt"]==""){
						o["receamt"]="0.00";
					}
					$("#totalreceamt").html(o["receamt"]);
					$("#tabdetail tr:first").next().find(
					"input[name='txbProductName']").focus();
				}
			});

		}
	}
	// 绑定供应商
	function bindsupplier(busiaction) {
		var autoCompleteTextbox = $("#txbCr");
		if (!!autoCompleteTextbox) {
			// 智能提示 编号、名称、规格、单位、条形码、库存数量
			var productheader = {
				suppliercode : "供应商编号",
				suppliername : "供应商名称"
					/*,
				supplierlink : "联系人",
				companytel : "单位电话",
				suppliertel:"联系电话",
				supplieraddress:"地址"*/
			};
			$("#txbCr").autoComplete({
				header : productheader,
				url : "/WBI-webapp/SupplierInfo/FuzzyQuery.htm?branchid=" + $("#choose-warehouse-parentval").val(),
				width : 400,
				businame:'cs',
				selected : function(o) {
					if ($("#choose-warehouse-val").val() == "") {
						showErrorMsg("请选择入库仓库!");
						return;
					}
					$("input[name='hidisgetnearprice']").val("0");
					$("#crvalue").val(o["supplierid"]);
					$("#txbCr").val(o["suppliername"]);
					$("#tabdetail tr:first").next().find(
					"input[name='txbProductName']").focus();
				}
			});

		}
	}
	function initBranchSelect(branchId, elementId,all,isAddAll) {
		if(isAddAll==undefined)
		{
			isAddAll=true;
		}
		var $obj = $("#" + elementId);
		if ($obj.length == 0) {
			return;
		}
		var requrl = "http://" + window.location.host+ "/WBI-webapp/Branch/getBranch.json";
		if(all==1){
			requrl = requrl + "?all="+all;
		}
		$.ajax({
			type : "POST",
			url : requrl,
			success : function(result, resultState) {
				if (resultState == "success") {
					if (result.serviceResult.statu == 1) {
						var branchHtml = "<option value=''>全部</option>";
						if(!isAddAll)
						{
							branchHtml="";
						}
						var branchList = result.serviceResult.rows;
						if (branchList != null) {
							var len = branchList.length;
							for (var i = 0; i < len; i++) {
								var branchname = branchList[i].branchname;
								if (branchname.length > 10) {
									branchname = branchname.substring(0, 10)
											+ '...';
								}
								if (branchId == branchList[i].branchid) {
									branchHtml += '<option value="'
											+ branchList[i].branchid + '"  selected>'
											+ branchname + '</option>';
								} else {
									branchHtml += '<option value="'
											+ branchList[i].branchid + '">'
											+ branchname + '</option>';
								}
							}
							$obj.empty();
							$obj.append(branchHtml);
						}
					} else {
						showMsg(result.serviceResult.message);
					}
				} else {
					alert("操作失败");
				}
			}
		});
	}
	
	
	$.fn.zTree.init($("#treeDemo1"), setting1);
	$.fn.zTree.init($("#treeDemo2"), setting2);
	
	var number=0;
	this.branch = Branch.loadBranchDropDownBox($("#branchSelect"), {
		defaultSelected : 0,
		defaultFlag : !0,
		editable : false,
		callback : {
			onChange : function(t) {
				if(number==0)
				{
					var name=$("#name").val();
					if(name=='')
					{
						name="全部门店";
					}
					$("#branchInput").val(name);
					number=number+1;
				}
				else
				{
					if(t.branchid=='0')
					{
						$("#branchid").val("");
					}
					else
					{
						$("#branchid").val(t.branchid);
					}
					list_reload();
					getTotal();
				}
			}
		}
	});

	
	Product.loadUnitDropDownBox = function($_obj, opts) {
		if ($_obj.length == 0) {
			return
		};
		var opts = $.extend(true, {
			data : function() {
				return 'UnitSetting/getCPUnittingByContactIdAndSOBId.htm';
			},
			ajaxOptions : {},
			width : 200,
			height : 300,
			formatText : function(row) {
				return row.unitname;
			},
			text : 'unitname',
			value : 'unitid',
			defaultSelected : -1,
			defaultFlag : false,
			cache : false,
			editable : true,
			forceSelection : false,
			callback : {
				onChange : function(data) {
				}
			},
			extraListHtml : ''
		}, opts);
		var unitCombo = $_obj.combo(opts).getCombo();
		return unitCombo;
	};
	// 载入属性下拉框
	Product.loadPropertyDropDownBox = function($_obj, opts,propertyname) {
		if ($_obj.length == 0) {
			return
		};
		var opts = $.extend(true, {
			data : function() {
				return 'ProductAttr/getDropDownBox.htm?propertyname='+propertyname;
			},
			ajaxOptions : {},
			width : 200,
			height : 300,
			formatText : function(row) {
				return row.propertytext;
			},
			text : 'propertytext',
			value : 'propertyid',
			defaultSelected : -1,
			defaultFlag : false,
			cache : false,
			editable : true,
			forceSelection : false,
			callback : {
				onChange : function(data) {
				}
			},
			extraListHtml : ''
		}, opts);
		var propertyCombo = $_obj.combo(opts).getCombo();
		return propertyCombo;
	};
	
	Business.saleTypeCombo = function($_obj, opts) {
	    if ($_obj.length == 0) {
	        return
	    };
	    var opts = $.extend(true, {
	        data: function() {
	            return [{
	                "text": "零售",
	                "value": "0"
	            },
	            {
	                "text": "批发",
	                "value": "1"
	            }];
	        },
	        ajaxOptions: {},
	        width: 60,
	        height: 300,
	        formatText: function(row) {
	            return row.text;
	        },
	        // formatResult: 'name',
	        text: 'text',
	        value: 'value',
	        defaultSelected: 0,
	        defaultFlag: false,
	        cache: false,
	        editable: false,
	        forceSelection: false,
	        callback: {
	            onChange: function(data) {}
	        },
	        extraListHtml: ''
	    },
	    opts);

	    var saleTypeCombo = $_obj.combo(opts).getCombo();
	    return saleTypeCombo;
	};
	Business.discountTypeCombo = function($_obj, opts) {
	    if ($_obj.length == 0) {
	        return
	    };
	    var opts = $.extend(true, {
	        data: function() {
	            return [{
	                "text": "折扣率",
	                "value": "0"
	            },
	            {
	                "text": "折扣额",
	                "value": "1"
	            }];
	        },
	        ajaxOptions: {},
	        width: 120,
	        height: 300,
	        formatText: function(row) {
	            return row.text;
	        },
	        text: 'text',
	        value: 'value',
	        defaultSelected: 0,
	        defaultFlag: false,
	        cache: false,
	        editable: false,
	        forceSelection: false,
	        callback: {
	            onChange: function(data) {}
	        },
	        extraListHtml: ''
	    },
	    opts);

	    var discountTypeCombo = $_obj.combo(opts).getCombo();
	    return discountTypeCombo;
	};